clear
use "D:\03 Data 3.dta"

/* Appendix B */
set more off
pscore merger log_daicho gpop log_area p_DID  p_old  p_young /*
*/ p_mochiie ind1 cons incomepc zaiseiryoku keijoshushi/*
*/  log_chihozeipc log_ttpc YotoVSrm, pscore(X)

/* Table 1 (1) */
drop if pcode==3 | pcode==4 | pcode==7 | pcode==1 | pcode==47 
drop if X==. 

sort X
tab merger if X<0.2 & X!=.
tab merger if X>=0.2 & X<0.4
tab merger if X>=0.4 & X<0.6
tab merger if X>=0.6 & X<0.8
tab merger if X>=0.8 & X<0.85
tab merger if X>=0.85 & X<0.9
tab merger if X>=0.9 & X!=.

gen g1=0 
replace g1=1 if X<0.2
gen g2=0
replace g2=1 if X>=0.2 & X<0.4
gen g3=0
replace g3=1 if X>=0.4 & X<0.6
gen g4=0
replace g4=1 if X>=0.6 & X<0.8
gen g5=0
replace g5=1 if X>=0.8 & X<0.85
gen g6=0
replace g6=1 if X>=0.85 & X<0.9
gen g7=0
replace g7=1 if X>=0.9

gen group=.
replace group=1 if g1==1
replace group=2 if g2==1
replace group=3 if g3==1
replace group=4 if g4==1
replace group=5 if g5==1
replace group=6 if g6==1
replace group=7 if g7==1

set more off
sort group

tab group merger

save "D:\temp.dta", replace

/* Table 1 (2) */
/*  Note: Municipalities randomly selected from the following procedutre will be likely different from
the ones that have been randomly selected for the current study.*/ 

clear
use "D:\temp.dta", clear

keep if merger==0
sample 1 if group==1, count
sample 1 if group==2, count
sample 3 if group==3, count
sample 17 if group==4, count
sample 9 if group==5, count
sample 8 if group==6, count
sample 7 if group==7, count
save "D:\temp2.dta", replace

clear
use "D:\temp.dta", clear
keep if merger==1
sample 1 if group==1, count
sample 1 if group==2, count
sample 3 if group==3, count
sample 17 if group==4, count
sample 9 if group==5, count
sample 8 if group==6, count
sample 7 if group==7, count

append using "D:\temp2.dta"

tab group merger
